package com.mall.order.web.config;

import com.mall.order.web.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author Administrator
 */
@Configuration
public class SpirngMvcConfig extends WebMvcConfigurerAdapter {

    /**
     * 配置dispatcherServlet的默认设置
     */

    @Bean
    public ServletRegistrationBean MySetting(DispatcherServlet dispatcherServlet) {
        ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
        //设置伪造静态页面
        registration.getUrlMappings().clear();
        registration.getUrlMappings().add("*.html");
        return registration;
    }

    @Autowired
    LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //千万要注意注册拦截器的时候如果拦截器中需要引用服务或者注入服务，在注册interceptor的时候千万不要new，而是
        //先把该拦截器放到IOC容器中，然后将其注入进配置类中进行配置
        registry.addInterceptor(loginInterceptor).addPathPatterns("/order/**");
    }


}
